package com.itheima.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dubbo.dao.BlackListDao;
import com.itheima.dubbo.dao.UserInfoDao;
import com.itheima.model.domain.BlackList;
import com.itheima.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private BlackListDao blackListDao;

    @Override
    public IPage<UserInfo> pageBlack(Long userId, int page, int size) {
        //创建分页构造器
        //1、构建分页参数对象Page
        Page pages = new Page(page, size);
        //2、调用方法分页（自定义编写 分页参数Page，sql条件参数）
        IPage<UserInfo> list = userInfoDao.findBlackList(pages, userId);
        return list;
    }

    @Override
    public void remove(Long userId, Long uid) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",uid);
        blackListDao.delete(qw);
//        LambdaQueryWrapper<BlackList> qw = Wrappers.lambdaQuery(BlackList.class);
//        qw.eq(BlackList::getUserId, userId);
//        qw.eq(BlackList::getBlackUserId, uid);
//        blackListDao.delete(qw);
    }
}
